package com.xuyang.other;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.graphics.drawable.AnimationDrawable;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.example.bookmanager.BrowseActivity;
import com.example.bookmanager.R;

public class ProgressDialog {
	private AlertDialog dialog;
	public ProgressDialog(Context context) {
			//加载进度框
				View view=LayoutInflater.from(context).inflate(R.layout.layout_dialog, null);
				ImageView imgProgress=(ImageView) view.findViewById(R.id.img_progress_bar);
				AnimationDrawable animationDrawable=(AnimationDrawable) imgProgress.getDrawable();
				animationDrawable.start();
				dialog=new AlertDialog.Builder(context)
						.setView(view)
						//设置不可取消
						.setCancelable(false)
						.create();
				dialog.show();
				dialog.getWindow().setLayout(dip2px(144,context), dialog.getWindow().getAttributes().height);
				Window window=dialog.getWindow();
				WindowManager.LayoutParams lp=window.getAttributes();
				lp.alpha=0.9f;
				window.setAttributes(lp);
	}
	public AlertDialog getDialog(){
		return dialog;
	}
	public int dip2px(float dpValue,Context context) {
		final float scale = context.getResources()
				.getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
}
